﻿using System.Windows.Forms;
using Presenter;
using Infrastructure;

namespace WinFormsUI
{
    public partial class MergeSortWinFormsView : Form, IView
    {
        public MergeSortWinFormsView()
        {
            InitializeComponent();
            new MergeSortPresenter(this, new LoggerToTxt());
            logTypeComboBox.SelectedIndex = 0;
        }

        public string inputArray
        {
            get { return inputArrayTextBox.Text; }
            set { inputArrayTextBox.Text = value; }
        }

        public string outputArray
        {
            get { return outputArrayTextBox.Text; }
            set { outputArrayTextBox.Text = value; }
        }

        public int selectedLogType
        {
            get { return logTypeComboBox.SelectedIndex; }
        }

        public void Attach(IPresenterCallbacks callback)
        {
            sortButton.Click += (sender, e) => callback.OnSort();
            showLogButton.Click += (sender, e) => callback.ShowLog();
            logTypeComboBox.SelectedIndexChanged += (sender, e) => callback.LogTypeChanged();
        }
        
        public void ShowMessageBox(string message)
        {
            MessageBox.Show(message);
        }

        public void ShowLog(string log)
        {
            LogView logView = new LogView(log);
            logView.Show();
        }

        public ILogger GetLoggerToTxt()
        {
            return (ILogger)new LoggerToTxt();
        }

        public ILogger GetLoggerToHtml()
        {
            return (ILogger)new LoggerToHtml();
        }
    }
}
